/*
============================================================================
 Name        : PhoneCallMaker2.cpp
 Author      : 王斌
 Version     :
 Copyright   : 益盟软件
 Description : CPhoneCallMaker2 implementation
============================================================================
*/

#include "PhoneCallMaker2.h"
#include "Logger.h"

CPhoneCallMaker2::CPhoneCallMaker2(MAnsPhoneCallMakerObserver& aObserver):
CActive(EPriorityNormal),iObserver(aObserver), iCallParamsPckg(iCallParams)
{
	CActiveScheduler::Add(this);

}


CPhoneCallMaker2::~CPhoneCallMaker2()
{
	Cancel();
	delete iTelephony;
}

CPhoneCallMaker2* CPhoneCallMaker2::NewLC(MAnsPhoneCallMakerObserver& aObserver)
{
	CPhoneCallMaker2* self = new (ELeave)CPhoneCallMaker2(aObserver);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CPhoneCallMaker2* CPhoneCallMaker2::NewL(MAnsPhoneCallMakerObserver& aObserver)
{
	CPhoneCallMaker2* self=CPhoneCallMaker2::NewLC(aObserver);
	CleanupStack::Pop(); // self;
	return self;
}

void CPhoneCallMaker2::ConstructL()
{

}

void CPhoneCallMaker2::RunL()
{
	//if(iCurrentStatus.iStatus == CTelephony::EStatusIdle ||
	//	iCurrentStatus.iStatus == CTelephony::EStatusDisconnecting)
	//{
	//	LOGCALL(iObserver.HandleCallHungUpL());
	//	return;
	//}
	//if(iStatus != KErrCancel)
	//{
	//	iCurrentStatus.iStatus = CTelephony::EStatusUnknown;
	//	iTelephony->NotifyChange(iStatus,CTelephony::EVoiceLineStatusChange,iCallParamsPckg);
	//	SetActive();
	//}
}

void CPhoneCallMaker2::DoCancel()
{
	LOGCALL(iTelephony->CancelAsync(CTelephony::EDialNewCallCancel));
}

void CPhoneCallMaker2::MakeCallL(const TDesC& aNumber)
{
	if(iTelephony != NULL)
		delete iTelephony;

	iTelephony = CTelephony::NewL();
	CTelephony::TTelNumber telNumber(aNumber);

	iCallParams.iIdRestrict = CTelephony::ESendMyId;
	
	LOGCALL(iTelephony->DialNewCall(iStatus, iCallParamsPckg, telNumber, iCallId));
	SetActive();

}
